var express=require('express');
var app=express();
var bodyParser=require('body-parser');
var url=require('url');

var urlencodeParser=bodyParser.urlencoded({extended:false});

app.use(express.static('public'));

app.get('/demo_post.html',function(req,res)
{
    res.sendFile(__dirname+"\\"+"demo_post.html");
    console.log(__dirname+"\\"+"demo_posts.html");
});

// app.post('/process_post',urlencodeParser,function(req,res)
// {
//     // 输出 JSON 格式
//     var response = {
//         "first_name":req.body.first_name,
//         "last_name":req.body.last_name
//     };
//     console.log(response);
//     res.end(JSON.stringify(response));
// });

app.post('/process_post',urlencodeParser,function(req,res)
{
    console.log("process_post");
   // var arg=url.parse(req.url).query;
    //console.log("parse>>",arg.first_name);
    var response={
        "first_name":req.body.first_name,
        "last_name":req.body.last_name
    };
    console.log(response);
    res.end(JSON.stringify(response));
});


var server = app.listen(8888, function () {

    var host = server.address().address
    var port = server.address().port

    console.log("应用实例，访问地址为 http://%s:%s", host, port)

})

